package commMqttRpc

import (
	"encoding/json"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/ChanSyncObj"
	mqtt "github.com/eclipse/paho.mqtt.golang"
)

type mqttHandler struct {
	clientId string
	topic    string
	router   map[string]interface{}
}

func (e *mqttHandler) Handler() mqtt.MessageHandler {
	return func(client mqtt.Client, msg mqtt.Message) {
		respondVO := &RestfulLikeRespondVO{}

		// 解码JSON
		err := json.Unmarshal(msg.Payload(), respondVO)
		if err != nil {
			return
		}
		respondVO.Topic = msg.Topic()

		// 通知消息到达
		ChanSyncObj.Notify(respondVO.Uuid, respondVO)
	}
}
